package com.animator.learn;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.util.Log;

public class ValueAnimatorTest {

	protected static final String TAG = ValueAnimatorTest.class.getSimpleName();

	public static void main(String[] args) {
		ValueAnimatorTest vat = new ValueAnimatorTest();
		
		vat.test1();
		
		vat.test2();
	}
	
	/*
	 * 将一个值从0平滑过渡到1
	 */
	public void test1() {
		ValueAnimator animFloat = ValueAnimator.ofFloat(0f, 1f);
		animFloat.setDuration(300);
		//添加监听更新器
		animFloat.addUpdateListener(new AnimatorUpdateListener() {
			@Override
			public void onAnimationUpdate(ValueAnimator animation) {
				float currentValue = (float)animation.getAnimatedValue();
				Log.d(TAG, "current: " + currentValue);
			}
		});
		animFloat.start();
		
	}

	/**
	 * 
	 */
	private void test2() {
		//
		ValueAnimator animInt = ValueAnimator.ofInt(1, 20, 100);
		animInt.setRepeatMode(ValueAnimator.RESTART);
		animInt.setRepeatCount(100);
		animInt.setStartDelay(1000L);
		
		animInt.addListener(new AnimatorListener() {
			
			@Override
			public void onAnimationStart(Animator animation) {
				
			}
			
			@Override
			public void onAnimationRepeat(Animator animation) {
				
			}
			
			@Override
			public void onAnimationEnd(Animator animation) {
				
			}
			
			@Override
			public void onAnimationCancel(Animator animation) {
				
			}
		});
		animInt.start();
	}

}
